<template>
  <a-card :bordered="false" >
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="借阅人">
              <a-input placeholder="" v-model="queryParam.jyr"   ></a-input>
            </a-form-item>
          </a-col>  
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button> 
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <!-- <div class="table-operator">
      <a-button type="primary" @click="searchQuery" icon="search">刷新</a-button> 
    </div> -->

    <!-- table区域-begin -->
    <div ref="page">
   

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:false}"
        bordered
        rowKey="id"
        
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record"> 
          <a @click="handleShow(record)">详情</a> 
          <a-divider type="vertical" v-if="record.czlx == '1'  && record.zt == '待审核'"  v-has="'sh:fysh'"/>
          <a @click="handleExamine(record)" v-if="record.czlx == '1'  && record.zt == '待审核'" v-has="'sh:fysh'">审核</a> 
          <a-divider type="vertical" v-if="record.czlx == '2'  && record.zt == '待审核'"  v-has="'sh:dycs'"/>
          <a @click="handleExamine(record)" v-if="record.czlx == '2' && record.zt == '待审核'" v-has="'sh:dycs'">初审</a> 
          <a-divider type="vertical" v-if="record.czlx == '2'  && record.zt == '初审核通过'"  v-has="'sh:dyfs'"/>
          <a @click="handleExamine(record)" v-if="record.czlx == '2'  && record.zt == '初审核通过'"  v-has="'sh:dyfs'">复审</a> 
        </span>

      </a-table>
    </div>  
    <da-jyxx ref="modalForm"></da-jyxx> 
    <a-modal
      :title="bt"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >
       <div class="ant-modal-confirm-body" style="padding-left: 40px;">
          <a-icon type="question-circle" style="color:#faad14"/>
          <span class="ant-modal-confirm-title">{{ModalText}}</span>
          <div class="ant-modal-confirm-content">{{tsxx}}</div>
          <div style="color:red;    margin-left: 10px;margin-top: 20px;">如拒绝请填写原因</div>
          <a-input v-model="shdata.bhyy" type="textarea" style="margin:10px;width:90%" />
       </div> 
       <template slot="footer">
        <div>
          <a-button type="danger"   @click="ModeOk(1)"  icon="check-circle" >通过</a-button>
          <a-button type="primary"   @click="ModeOk(2)"  icon="stop" >拒绝</a-button>
          <a-button    @click="ModeCanel(1)"  icon="close" >取消</a-button>
        </div>
      </template>
    </a-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import DaJyxxModal from './modules/DaJyxxModal'
  import DaSqRyxxList from './modules/DaList' 
  import DaJyxx from './modules/DaJyxx'
  import store from '@/store/'
  import Watermark from '@/utils/watermark'
  import { httpAction, getAction,deleteAction } from '@/api/manage'  
  
  export default {
    name: 'DaJyxxList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      DaJyxxModal,
      DaSqRyxxList, 
      DaJyxx
    },
    data () {
      return {
        ModalText: 'Content of the modal',
        visible: false,
        shdata:{
          id:'',
          zt : '',
          createby: '',
          jyr: '',
          bhyy : '',
          bjyrid: '',
        },
        bt:'',
        tsxx:'',
        confirmLoading: false,
        description: '复印调档表管理页面',
        // 表头
        columns: [ 
          
        {
            title:'姓名',
            align:"center", 
            dataIndex: 'bjyrxm',
          },
          {
            title:'身份证号',
            align:"center", 
            dataIndex: 'bjyrsfzh',
          },
          {
            title:'入伍时间',
            align:"center", 
            dataIndex: 'bjyrrwsj',
          },
          {
            title:'退伍时间',
            align:"center", 
            dataIndex: 'bjyrtwsj',
          },
          {
            title:'联系电话',
            align:"center", 
            dataIndex: 'bjyrlxdh',
          },
          {
            title:'申请原因',
            align:"center", 
            dataIndex: 'sqyy',
          },
          {
            title:'操作类型',
            align:"center", 
            dataIndex: 'czlx_dictText',
          },
          {
            title:'申请时间',
            align:"center", 
            dataIndex: 'createTime',
          },
          {
            title:'状态',
            align:"center",
            dataIndex: 'zt'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/dajy/daJyxx/fllist?czlx=1",
          delete: "/dajy/daJyxx/delete",
          deleteBatch: "/dajy/daJyxx/deleteBatch",
          exportXlsUrl: "/dajy/daJyxx/exportXls",
          importExcelUrl: "/dajy/daJyxx/importExcel",
          shenhe:"/dajy/daJyxx/jyshenhe"
          
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
        this.getSuperFieldList(); 
        setTimeout(() => {
          Watermark.set(store.getters.water , this.$refs.page)
          
        }, 1000);
        
    },
    computed: {
      
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
       
    },
    methods: { 
      clearrXM(){
        this.shdata.id = "";
        this.shdata.zt = "";
        this.shdata.createby = "";
        this.shdata.jyr = "";
        this.shdata.bhyy = "";
        this.shdata.bjyrid = "";
      },
      ModeOk(e){
        let zt = "";
        if (e == 2){
          if (this.shdata.bhyy == ""){
            this.$message.success("请填写驳回原因");
            return;
          }
        }
        if (this.bt == "审核"){zt = "1"}
        if (this.bt == "初审"){zt = "2"}
        if (this.bt == "复审"){zt = "3"}

        if (e == 1){zt += "1"}
        if (e == 2){zt += "0"}
        this.shdata.zt = zt; 
        httpAction(this.url.shenhe,this.shdata,'post').then((res)=>{ 
            if (res.code == "0"){
              this.$message.success("审核完成");
              this.clearrXM();
              this.loadData();
              this.visible = false; 
            }
          }).finally(() => { 
            this.loading = false;
        }) 
      },
      ModeCanel(){
        this.visible = false;
      },
      handleOk(e) {
        this.ModalText = 'The modal will be closed after two seconds';
        this.confirmLoading = true;
        setTimeout(() => {
          this.visible = false;
          this.confirmLoading = false;
        }, 2000);
      },
      handleCancel(e) {
        console.log('Clicked cancel button');
        this.visible = false;
      },
      handleExamine(record){
        console.log(record)
        let title = "";
        if(record.czlx == "1"){
          title = "复印档案审核";
          this.bt = "审核";
          this.tsxx = "申请人："+record.bjyrxm;
        }
        if(record.czlx == "2"){
          title = "调用档案";
          if(record.zt == "待审核"){
            title +="初审";
            this.bt = "初审";
            this.tsxx = "申请人："+record.jyr;
          }
          if(record.zt == "初审核通过"){
            title +="复审";
            this.bt = "复审";
            this.tsxx = "申请人："+record.jyr;
          }
        }
        this.shdata.id = record.id;
        this.shdata.createby = record.createBy;
        this.shdata.jyr = record.jyr;
        this.shdata.bjyrid = record.bjyrid;
        this.ModalText = title;
        this.visible = true;
        
        // this.$confirm({
        //   title: title,
        //   content: "申请人："+record.jyr,
        //   showCancel:true,
        //   maskClosable:true,
        //   okText: '通过',
        //   okType: 'danger',
        //   cancelText: '拒绝',
        //   onOk() {
        //     console.log('OK');
        //   },
        //   onCancel() {
        //     console.log('Cancel');
        //   },
        // });
      },
      handleShow(record){
        this.$nextTick(()=>{
          this.$refs.modalForm.show(record.id);
        })
      },
      modalFormOk(){
        this.loadData();
        this.clearrXM();
        console.log('返回刷新');
      },
      handleSearch(){
        
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'czlx',text:'操作类型',dictCode:'czlx'})
        fieldList.push({type:'string',value:'jyr',text:'借阅人'})
        fieldList.push({type:'string',value:'zt',text:'状态'})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>